package structures;

import java.util.List;
import java.util.Map;

import domain.OrgKullaniciDAO;
import exception.IBToolsException;
import manager.ScreenDAOManager;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 * Dummy implementation of LazyDataModel that uses a list to mimic a real datasource like a database.
 */
public class LazyOrgKullaniciDAODataModel extends LazyDataModel<OrgKullaniciDAO> {
    
    private List<OrgKullaniciDAO> datasource;
	private OrgKullaniciDAO searchKullanici;
    
    public LazyOrgKullaniciDAODataModel(OrgKullaniciDAO searchKullanici) {
        this.searchKullanici = searchKullanici;
    }
    
    @Override
    public OrgKullaniciDAO getRowData(String rowKey) {
        for(OrgKullaniciDAO kullanici : datasource) {
            if(kullanici.getOid().equals(rowKey))
                return kullanici;
        }

        return null;
    }

    @Override
    public Object getRowKey(OrgKullaniciDAO kullanici) {
        return kullanici.getOid();
    }

    @Override
    public List<OrgKullaniciDAO> load(int start, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
        try {
			datasource = ScreenDAOManager.findKullanici(searchKullanici, start, pageSize, sortField, sortOrder);
	        setRowCount(ScreenDAOManager.findKullaniciCount(searchKullanici, start, pageSize, sortField, sortOrder));
		} catch (IBToolsException e) {
			e.printStackTrace();
		}
        return datasource;
    }
    
    
}
                    